<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: LJQ <245369209@qq.com> 
// +----------------------------------------------------------------------

namespace app\inspection\model;
use app\common\model\Base;
use app\basic\model\Staff;

/**
 * 巡检任务
 */
class Mission extends Base{

	protected $name = "inspectionmission";
	protected $createTime = 'createTime';
	protected $updateTime = 'updateTime';
	
	
	public function getAreaList() {
		$areaList = db('basicinfo')->where('sysCode',2)->column('subsystemName','subsystemNo');
		return $areaList;
	}
	
	public function getAreaIdAttr($value,$data) {
		if($data['areaId']){
			$areaList = $this->getAreaList();
			return $areaList[$data['areaId']];
		}
		return null;
	}
	
	public function user(){

		return $this->hasOne('app\common\model\User','id','chargePerson');
	}
	
	public function items(){
		return $this->belongsToMany('Item','inspectiondetail','inspectionItemId','inspectionMissionId');
	}
	
	public function enterprise() {
		return $this->hasOne('app\basic\model\Enterprise','id','enterpriseId');
	}
	
}